#include <linux/module.h>
#include <linux/major.h>
#include <linux/types.h>
#include <linux/errno.h>
#include <linux/delay.h>	/* guess what */
#include <linux/fs.h>
#include <linux/mm.h>
#include <linux/init.h>
#include <linux/device.h>
#include <linux/mutex.h>
#include <linux/firmware.h>
#include <linux/platform_device.h>

#include <linux/module.h>
#include <linux/init.h>
#include <linux/file.h>
#include <linux/blkdev.h>
#include <linux/poll.h>
#include <linux/cdev.h>
#include <linux/jiffies.h>
#include <linux/percpu.h>
#include <linux/uio.h>
#include <linux/idr.h>
#include <linux/bsg.h>
#include <linux/slab.h>


char readBuff[] = "is内核数据";
char writeBuff[50];

static int charbase_open(struct inode *inode, struct file *file)
{
    return 0;
}
static ssize_t cahrbase_read (struct file * file, char __user * buff, size_t size, loff_t * loff)
{
    copy_to_user(buff,readBuff,size);
    return 0;
}
static ssize_t charbase_write (struct file * file, const char __user * buff, size_t size, loff_t * loff)
{
    copy_from_user(writeBuff,buff,size);
    printk("内核接受：%s\r\n",writeBuff);
    return 0;
}
static int charbase_release (struct inode * inode, struct file * file)
{
    return 0;
}
static const struct file_operations charbase_fops = {
	.owner = THIS_MODULE,
	.open = charbase_open,
	.read = cahrbase_read,
    .write = charbase_write,
	.release = charbase_release,
};
static int __init charbase_init(void)
{
    printk("载入测试驱动\r\n");
    int ret = 0;
    ret=register_chrdev(200,"charbase",&charbase_fops);
    if(ret<0)
        printk("载入测试驱动失败!\r\n");
    return 0;
}
static void __exit charbase_exit(void)
{
    printk("卸载测试驱动\r\n");
    unregister_chrdev(200,"charbase");
    return;
}

MODULE_AUTHOR("Xiao");
MODULE_LICENSE("GPL");

module_init(charbase_init);
module_exit(charbase_exit);